﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using OAuth;
using Darren.Common.Helper;

public partial class NetEasyDemo : System.Web.UI.Page
{
    NetEasyOAuth auth = new NetEasyOAuth();
    protected void Page_Load(object sender, EventArgs e)
    {
        string oauth = CookieHelper.GetCookieValue("NetEasyOAuth");
        string token = StringHelper.QueryString(oauth, "Token");
        string token_secret = StringHelper.QueryString(oauth, "TokenSecret");
        string openId = StringHelper.QueryString(oauth, "OpenID");

        Response.Write(string.Format("access_oauth_token={0}<br/>access_oauth_token_secret={1}<br/>access_openid={2}<br/>",
        token,
        token_secret,
        openId));

        auth.UserRemoteIP = Request.UserHostAddress;
        auth.Token = new AccessToken(token, token_secret, openId);
    }

    protected void btnGetInfo_Click(object sender, EventArgs e)
    {
        MemberInfo info= auth.GetUserInfo();
        Response.Write(string.Format("{0}:{1}<br/><img src='{2}'/>",info.MemberID,info.DisplayName,HttpUtility.UrlDecode(info.ImageUrl)));
    }
    protected void btnUpdateSina_Click(object sender, EventArgs e)
    {
        string content = txtSinaStatus.Text;
        string info = auth.UpdateStatus(content);
        TextBox1.Text = info;
    }
    protected void btnGetFriends_Click(object sender, EventArgs e)
    {
        TextBox1.Text = auth.GetFriends(txtFriendsName.Text);
    }
    protected void btnCreateFriendship_Click(object sender, EventArgs e)
    {
        TextBox1.Text = auth.FriendshipCreate(txtFriendshipID.Text);
    }
}